package view.plugin
{
	//玩家信息
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import global.Resource;
	
	import vo.UserInfo;
	import vo.UserScore;
	
	public class PlayerInfoPanel extends Sprite
	{
		private var playerInfo:MovieClip = null;
		private var parents:DisplayObjectContainer;
		private var userInfo:UserInfo;
		private var userScore:UserScore;
		public static var playerInfoPanel:PlayerInfoPanel;
		public function PlayerInfoPanel(par:DisplayObjectContainer = null)
		{
			super();
			playerInfo = Resource.i.getMovieClip("common", "PlayerInfo");
			addChild(playerInfo);
			parent = par;
		}
		static public function get i():PlayerInfoPanel
		{
			if(!playerInfoPanel)
				playerInfoPanel = new PlayerInfoPanel();
			return playerInfoPanel;
		}
		public function set parent(par:DisplayObjectContainer):void
		{
			if(!par && parents && parents != par)
			{
				parents.removeEventListener(MouseEvent.MOUSE_OVER, onMouseOverParent);
				parents.removeEventListener(MouseEvent.MOUSE_OUT, onMouseOutParent);
			}

			parents = par;
			if(parents)
			{
				parents.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverParent);
				parents.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutParent);
			}
		}
		override public function get parent():DisplayObjectContainer
		{
			return parents;
		}
		public function setData(userInfo:UserInfo, userScore:UserScore):void
		{
			this.userInfo = userInfo;
			this.userScore = userScore;
		}
		public function updateData():void
		{
			if(!userScore) return;
			playerInfo.txtGold.text		= userScore.lGoldScore.toString();
			playerInfo.txtMaoGold.text	= userScore.lScore.toString();
		}
		private function onMouseOverParent(evt:MouseEvent):void
		{
			if(parent)
			{
				updateData();
				parent.addChild(this);
			}
		}
		private function onMouseOutParent(evt:MouseEvent):void
		{
			if(parent && parent.contains(this))
				parent.removeChild(this);
		}
	}
}